import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Md5 } from 'ts-md5/dist/md5';
import { ApiProvider } from '../../providers/api/api'
import { Storage } from '@ionic/storage';

/**
 * Generated class for the UserCashRecordPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
    selector: 'page-user-cash-record',
    templateUrl: 'user-cash-record.html',
})
export class UserCashRecordPage {
    public uid: any;
    public resData:any = {};
    public Arr: Array<any>;
    public noData:boolean = false;


    constructor(
        public navCtrl: NavController, 
        public navParams: NavParams,
        public Api: ApiProvider,
        public storage: Storage) {

        storage.get('userId').then(
            (value: string) => {
                this.uid = value
            }
        );
    }

    ionViewDidEnter() {
        this.PostData();
    }

    PostData() {
        let timeStamp = (new Date()).getTime();
        if (this.uid) {
            this.Api.cashRecord({
                times: timeStamp,
                token: Md5.hashStr('HalfPriceMall' + timeStamp),
                put: 'put',
                userid: this.uid,
                page: 1,
                count: 20,
            }).then(res => {
                this.resData = res;
                if ( this.resData.code == 1 ) {
                    this.Arr = this.resData.data;
                    this.noData = false;
                } else {
                    this.noData = true;
                }
            })
        }
    }



}
